package com.chezhujie.www.service;

import com.chezhujie.www.domain.Czjdiscount;
import com.chezhujie.www.persistence.CzjdiscountMapper;
import com.xy.core.page.Pagination;
import com.xy.core.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("CzjdiscountService")
public class CzjdiscountService {
	@Autowired
	private CzjdiscountMapper czjdiscountMapper;

	/**
	 * 查询某个czj_discount  优惠
	 * @param param
	 * @return
	 */
	public Czjdiscount getCzjdiscount(Map<String,Object> param) {
		return czjdiscountMapper.getCzjdiscount(param);
	}
	
	/**
	 * 查询某个czj_discount  优惠
	 * @param param
	 * @return
	 */
	public List<String> getCzjdiscountALL() {
		return czjdiscountMapper.getCzjdiscountALL();
	}	
   
	/**
	 * 查询某个czj_discount  优惠queryImgOrder
	 * @param param
	 * @return
	 */
	public Czjdiscount queryImgOrder(Map<String,Object> param) {
		return czjdiscountMapper.queryImgOrder(param);
	}	
	
	/**
	 * 查询czj_discount  优惠列表
	 * @return
	 */
	public Map<String,Object> getCzjdiscountList(Map<String,Object> param) {
		Map<String,Object> returnMap = new HashMap<String,Object>();
		returnMap.put("totalCounts", czjdiscountMapper.getTotalRows(param));
		returnMap.put("list", czjdiscountMapper.getCzjdiscountList(param));
		return returnMap;
	}
   
	
	/**
	 * 查询czj_discount  优惠列表
	 * @return
	 */
	public  List<Czjdiscount> getCzjdiscountListALL(Map<String,Object> param) {
		List<Czjdiscount> list=	czjdiscountMapper.getCzjdiscountListALL(param);
		return list;
		
	}	
	
	
	
	/**
	 * 查询czj_discount  优惠列表
	 * @return
	 */
	public  Pagination getCzjdiscountList(Map<String,Object> param,int pageSize,Integer pageNo,String order,String sort) {
		Pagination p = new Pagination();
		p.setPageNo(pageNo);
		p.setPageSize(pageSize);
		p.setOrder(order);
		p.setSort(sort);
		param.putAll(p.toMap());
		int count=czjdiscountMapper.getTotalRows(param);
		List<Czjdiscount> list=	czjdiscountMapper.getCzjdiscountList(param);
	
		p.setList(list);
		p.setTotalCount(count);
		return p;
		
	}
      
	/**
	 * 新增czj_discount  优惠
	 * @param czjdiscount
	 * @param param
	 */
	@Transactional
	public void insertCzjdiscount(Czjdiscount czjdiscount) {	
		czjdiscount.setDiscountId(UUIDUtils.getUUID());
		czjdiscountMapper.insertCzjdiscount(czjdiscount);
	}
   
	/**
	 * 编辑czj_discount  优惠
	 * @param czjdiscount
	 * @param param
	 */
	@Transactional
	public void updateCzjdiscount(Czjdiscount czjdiscount) {
		czjdiscountMapper.updateCzjdiscount(czjdiscount);
	}
   
	/**
	 * 删除czj_discount  优惠
	 * @param param
	 */    
	@Transactional
	public void deleteCzjdiscount(List<String> discountIdList) {
		for(String discountId: discountIdList){
	  		Map<String,Object> param = new HashMap<String,Object>();
	  		param.put("discountId", discountId);
	 	   czjdiscountMapper.deleteCzjdiscount(param);	  		
		}
	}


}